/**
 * 版权所有 2009-2012山东新北洋信息技术股份有限公司
 * 保留所有权利。
 */
package com.linyaonan.leetcode.easy._52_new;

/**
 * @ProjectName: leetcode
 * @Package: com.linyaonan.leetcode.easy._52_new
 * @ClassName: Get
 * @Author: linyaonan
 * @Date: 2020/3/26 14:39
 */
public class Get {

    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode l1 = headA;
        ListNode l2 = headB;
        while (!(l1 == null && l2 == null)) {
            if (l1 == l2) {
                return l1;
            }
            if (l1 != null) {
                l1 = l1.next;
            } else {
                l1 = headB;
            }
            if (l2 != null) {
                l2 = l2.next;
            } else {
                l2 = headA;
            }
        }
        return null;
    }

}
